using Godot;
using System;

namespace Box;
public partial class StringPropertyControl : HBoxContainer,IProperty
{
	[Signal]
	public delegate void onChangeEventHandler(string new_value);

	public string pvalue = "";
	public object PValue {
		get {
			
			if(Input == null) return pvalue;
			return Input.Text;
		}

		set {
			if(((string)value) != pvalue) {
				EmitSignal(nameof(onChange),(string)value);
			}
			if(Input == null) {
				pvalue = (String)value;
				return;
			}
			Input.Text = (String)value;
		}
	}

	public string PName {get;set;}

	Label label;
	public LineEdit Input;

	public override string ToString() {
		return PValue.ToString();
	}
	public override void _Ready()
	{
		Input = GetNode<LineEdit>("Input");
		label = GetNode<Label>("Label");
		label.Text = PName;
		Input.Text = pvalue;
	}
}
